<?php

require_once "OPDatabase.php";

class Team {
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Attributes
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Id of the team
	 * 
	 * @var int
	 */
	protected $id = null;
	
	/**
	* Color of the team
	*
	* @var String
	*/
	public $color;
	
	/**
	 * -------------------------------------------------------------------------
	 * 
	 * 									Static
	 * 
	 * -------------------------------------------------------------------------
	 */
	
	/**
	* -------------------------------------------------------------------------
	* 									Constructeur
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Static constructor creating a new Team with a color
	*
	* @param $color
	* @return Team
	*/
	public static function newWithColor($color){
		$newTeam	= new Team();
				
		$newTeam->setColor($color);
		
		return $newTeam;	
	
	}
	
	/**
	* Static constructor creating a new Team with an id and a color
	*
	* @param $id, $color
	* @return Team
	*/
	public static function newWithIdAndColor($id, $color){
		$newTeam	= self::newWithColor($color);
	
		$newTeam->setId($id);
	
		return $newTeam;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	

	
	/**
	* -------------------------------------------------------------------------
	* 								Occupation Calcul
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Calculates occupation for the specified team
	 * 
	 * @param $team
	 * @return percentage
	 */
	public static function occupationForTeam($team) {
		return OPDatabase::occupationForTeam($team);
		
	}
	
	
	/**
	* -------------------------------------------------------------------------
	*
	* 									Dynamic
	*
	* -------------------------------------------------------------------------
	*/
	
	/**
	* -------------------------------------------------------------------------
	* 									Setters
	* -------------------------------------------------------------------------
	*/
	
	/**
	* Set team's id
	*
	* @param $id
	* @return Team
	*/
	public function setId($id) {
		$this->id = $id;
	
		return $this;
	
	}
	
	/**
	* Set team's color
	*
	* @param $color
	* @return Team
	*/
	public function setColor($color) {
		$this->color = $color;
		
		return $this;
	
	}
	
	/**
	* -------------------------------------------------------------------------
	* 									Getters
	* -------------------------------------------------------------------------
	*/
	
	/**
	 * Return the id of the team
	 * 
	 * @return int
	 */
	public function id() {
		return $this->id;
		
	}
	
	/**
	* Return the color of the team
	*
	* @return string
	*/
	public function color() {
		return $this->color;
	
	}
	
	/**
	* Return the % of occupation owned by the team
	*
	* @return float
	*/
	public function occupation() {
		return OPDatabase::occupationForTeam($this->id());
	
	}

	/**
	* -------------------------------------------------------------------------
	* 									Database
	* -------------------------------------------------------------------------
	*/
	
	public function save() {
		OPDatabase::saveTeam($this);
	
	}
	
}